'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
    //event为客户端上传的参数
    
    const collection = db.collection('opendb-news-articles')

    // 总条数
    let total = await collection.where({ categoryId: event.category_id }).count()

    // 获取新闻列表
    let start = (event.currentPage - 1) * event.pageSize
    let res = await collection.where({ category_id: event.category_id }).orderBy('date', 'desc').skip(start).limit(event.pageSize).get();
    console.log('event : ', event)

    // 返回数据给客户端
    return {
        total: total.total,
        list: res.data
    }
};